// pages/calendarDetails/calendarDetails.js
const api = require('../../utils/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    newsInfo:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCalendarInfoList(options.newsId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  onShow:function(){
    
  },

  getCalendarInfoList(newsId){
    api.getCalendarDetails({
      "NewsID":newsId
    }).then(res=>{
      //console.log(res);
      if(res.data.code != 0) return;
      let info = res.data.data[0];
      if(!info.Content.indexOf('杭州日历')) {
        this.getCalendarHangZhou(info.Content.substr(5));
        return
      }
      info.Content = info.Content.replace(/\<img/gi, '<img class="rich_img" ')
      info.FlagPic = 'http://big-file.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/' + info.FlagPic;
      this.setData({
        newsInfo:info
      })
    })
  },
  getCalendarHangZhou(newsId){
    api.getCalendarHangZhou(newsId).then(res=>{
      console.log(res)
      if(res.statusCode!==200) return
      let info = res.data.data.attributes;
      info.SendDate = info['commenced-at'].substr(0,10);
      info.IsNew = info['terminated-at'].substr(0,10);
      info.FlagPic = info['featured-image'];
      info.content = info.content.replace(/\<img/gi, '<img class="rich_img" ');
      info.ComFrom = info.address
      this.setData({
        newsInfo:info
      })
    })
  }
})